package com.atguigu.jxc.controller;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;
import java.util.*;

/**
 * 客户基础资料查询
 */
@RestController
@RequestMapping("customer")
public class CustomerController {
    @Autowired
    CustomerService customerService;

    /**
     * 分页 模糊查询客户
     * @param page
     * @param rows
     * @param customerName
     * @return
     */
    @PostMapping("/list")
    private Map<String,Object> list(Integer page,Integer rows,String customerName){
       List<Customer> customers = customerService.list((page-1*rows),rows,customerName);
        int size = customers.size();

        Map<String,Object> map = new HashMap();

        map.put("rows",customers);
       return map;
    }

    /**
     * 保存或者修改客户
     * @param customer
     */
    @PostMapping("save")
    private void save( Customer customer){
        customerService.save(customer);
    }
    /***
     * 删除客户支持批量删除
     */
    @PostMapping("delete")
    private void delete(String ids){
        //分割参数存储集合中
        List<String> list = Arrays.asList(ids.split(","));
        customerService.delete(list);
    }
}
